package test;

import io.rsocket.Payload;
import io.rsocket.RSocket;
import io.rsocket.core.RSocketConnector;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.util.DefaultPayload;
import reactor.core.publisher.Mono;

public class Client {

    public static void main(String[] args) throws Exception {
        Mono<RSocket> rSocketMono = RSocketConnector.connectWith(TcpClientTransport.create(10010));
        RSocket rSocket = rSocketMono.block();

        rSocket.requestStream(DefaultPayload.create("Hello"))
                .map(Payload::getDataUtf8)
                .take(5)
                .doOnNext(s -> System.out.println(s))
                .doFinally(signalType -> rSocket.dispose())
                .subscribe((s) -> System.out.println(s),
                        e -> {
                            e.printStackTrace();
                        },
                        () -> {
                            System.out.println("Completed!");
                        });


        synchronized (rSocket) {
            rSocket.wait();
        }
    }
}
